package CPOO;

import java.awt.Point;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DropTarget;
import java.awt.dnd.DropTargetDragEvent;
import java.awt.dnd.DropTargetDropEvent;
import java.awt.dnd.DropTargetEvent;
import java.awt.dnd.DropTargetListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Logger;

import javax.swing.JFileChooser;
import javax.swing.JRadioButtonMenuItem;

import CPOO.ImageFilter;
import ij.ImagePlus;
import javax.imageio.ImageIO;

public class MainWindow extends javax.swing.JFrame {
	private final static Logger LOGGER = Logger.getLogger(MainWindow.class
			.getName());
	/*
	 * Tutaj zapisywane sa pliki i jest do nich dostep z innych klas, nie
	 * robilem oddzielnej klasy obraz czy cos takiego
	 */
	public ArrayList<AlgorithmInterface> algorithmsList;
	public ArrayList<File> picturesList;
	public ArrayList<File> picturesAfterAlgorithmList;
	public BufferedImage image;
	public BufferedImage image_pr;
	public DropTarget dropTarget;
	public DropTarget dropTarget2;
	public ImageFilter imageFileter;
	
	public MainWindow() {
		picturesList = new ArrayList<>();
		picturesAfterAlgorithmList = new ArrayList<>();
		algorithmsList = new ArrayList<>();
		algorithmsList.add(new ClaheInterface()); 
		algorithmsList.add(new HistogramEQInterface());
		imageFileter=new ImageFilter();
		initComponents();

		
		
		dropTarget = new DropTarget(this, new MyDropListener());
		
		this.setLocation(200, 200);
		this.setVisible(true);
		
		//picturesAfterAlgorithmList = picturesList; // roboczo, póki nie ma
													// algorytmu
	}

	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed"
	// desc="Generated Code">//GEN-BEGIN:initComponents
	private void initComponents() {

		navigationPanel = new javax.swing.JPanel();
		algorithmChooseComboBox = new javax.swing.JComboBox();
		algorithmChooseLabel = new javax.swing.JLabel();
		navigationSeparator0 = new javax.swing.JSeparator();
		navigationSeparator1 = new javax.swing.JSeparator();
		algorithStartButton = new javax.swing.JButton();
		picturesAftertButton = new javax.swing.JButton();
		picturesComparetButton = new javax.swing.JButton();
		pictureBeforeButton = new javax.swing.JButton();
		picturesBeforeLabel = new javax.swing.JLabel();
		picturesAfterLabel = new javax.swing.JLabel();
		pictureCompareLabel = new javax.swing.JLabel();
		parametersPanel = new javax.swing.JPanel();
		algorithmParametersText = new javax.swing.JTextArea();
		picturesPathPanel = new javax.swing.JPanel();
		picturesPathLabel = new javax.swing.JLabel();
		picturesPathExplicite = new javax.swing.JTextField();
		picturesPathButton = new javax.swing.JButton();
		mainMenuBar = new javax.swing.JMenuBar();
		fileMenu = new javax.swing.JMenu();
		newWindowMEnuItem = new javax.swing.JMenuItem();
		saveAfterMenuItem = new javax.swing.JMenuItem();
		exitMenuItem = new javax.swing.JMenuItem();
		picturesMenu = new javax.swing.JMenu();
		helpMenu = new javax.swing.JMenu();
		FAQMenuItem = new javax.swing.JMenuItem();
		teamMembersMenuItem = new javax.swing.JMenuItem();
		instructionMenuItem = new javax.swing.JMenuItem();
		documentationMenuItem = new javax.swing.JMenuItem();

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
		setTitle("Poprawa kontrastu");
		setBackground(new java.awt.Color(204, 204, 255));
		setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
		setMaximumSize(new java.awt.Dimension(500, 420));
		setMinimumSize(new java.awt.Dimension(500, 420));
		setPreferredSize(new java.awt.Dimension(500, 420));
		setResizable(false);

		navigationPanel.setBorder(javax.swing.BorderFactory
				.createTitledBorder("Wybór opcji"));
		// Kangur - binding listy algorytmow do comboboxa TODO
		Iterator<AlgorithmInterface> itr = algorithmsList.iterator();
		javax.swing.DefaultComboBoxModel mod = new javax.swing.DefaultComboBoxModel();
		while (itr.hasNext()) {
			mod.addElement(itr.next().getName());
		}
	
		algorithmChooseComboBox.setModel(mod);
		// -----------------------------------

		algorithmChooseComboBox
				.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent evt) {
						algorithmChooseComboBoxActionPerformed(evt);
					}
				});

		algorithmChooseLabel.setText("Wybór algorytmu");

		algorithStartButton.setText("Start algorytmu");
		algorithStartButton
				.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent evt) {
						algorithStartButtonActionPerformed(evt);
					}
				});

		picturesAftertButton.setText("Obrazy PO");
		picturesAftertButton
				.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent evt) {
						picturesAftertButtonActionPerformed(evt);
					}
				});

		picturesComparetButton.setText("Porównaj");
		picturesComparetButton
				.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent evt) {
						picturesComparetButtonActionPerformed(evt);
					}
				});

		pictureBeforeButton.setText("Obrazy PRZED");
		pictureBeforeButton
				.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent evt) {
						pictureBeforeButtonActionPerformed(evt);
					}
				});

		picturesBeforeLabel.setText("Pokaż obrazy PRZED poprawą kontrastu");

		picturesAfterLabel.setText("Pokaż obrazy PO poprawie kontrastu");

		pictureCompareLabel.setText("Pokaż porównanie obrazów");

		javax.swing.GroupLayout navigationPanelLayout = new javax.swing.GroupLayout(
				navigationPanel);
		navigationPanel.setLayout(navigationPanelLayout);
		navigationPanelLayout
				.setHorizontalGroup(navigationPanelLayout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								navigationPanelLayout
										.createSequentialGroup()
										.addGroup(
												navigationPanelLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addGroup(
																navigationPanelLayout
																		.createSequentialGroup()
																		.addGroup(
																				navigationPanelLayout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.LEADING)
																						.addGroup(
																								navigationPanelLayout
																										.createSequentialGroup()
																										.addGap(21,
																												21,
																												21)
																										.addComponent(
																												algorithStartButton,
																												javax.swing.GroupLayout.PREFERRED_SIZE,
																												209,
																												javax.swing.GroupLayout.PREFERRED_SIZE))
																						.addGroup(
																								navigationPanelLayout
																										.createSequentialGroup()
																										.addContainerGap()
																										.addComponent(
																												picturesBeforeLabel)))
																		.addGap(0,
																				0,
																				Short.MAX_VALUE))
														.addGroup(
																navigationPanelLayout
																		.createSequentialGroup()
																		.addContainerGap()
																		.addGroup(
																				navigationPanelLayout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.LEADING)
																						.addComponent(
																								algorithmChooseComboBox,
																								0,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								Short.MAX_VALUE)
																						.addComponent(
																								navigationSeparator0)
																						.addComponent(
																								navigationSeparator1)
																						.addGroup(
																								navigationPanelLayout
																										.createSequentialGroup()
																										.addGroup(
																												navigationPanelLayout
																														.createParallelGroup(
																																javax.swing.GroupLayout.Alignment.LEADING)
																														.addComponent(
																																algorithmChooseLabel,
																																javax.swing.GroupLayout.PREFERRED_SIZE,
																																133,
																																javax.swing.GroupLayout.PREFERRED_SIZE)
																														.addComponent(
																																picturesAfterLabel)
																														.addComponent(
																																pictureCompareLabel)
																														.addComponent(
																																picturesAftertButton,
																																javax.swing.GroupLayout.PREFERRED_SIZE,
																																120,
																																javax.swing.GroupLayout.PREFERRED_SIZE)
																														.addComponent(
																																picturesComparetButton,
																																javax.swing.GroupLayout.PREFERRED_SIZE,
																																120,
																																javax.swing.GroupLayout.PREFERRED_SIZE))
																										.addGap(0,
																												0,
																												Short.MAX_VALUE)))))
										.addContainerGap())
						.addGroup(
								navigationPanelLayout
										.createSequentialGroup()
										.addContainerGap()
										.addComponent(
												pictureBeforeButton,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												120,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addContainerGap(
												javax.swing.GroupLayout.DEFAULT_SIZE,
												Short.MAX_VALUE)));
		navigationPanelLayout
				.setVerticalGroup(navigationPanelLayout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								navigationPanelLayout
										.createSequentialGroup()
										.addContainerGap()
										.addComponent(
												algorithmChooseLabel,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												15,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addComponent(
												algorithmChooseComboBox,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
										.addComponent(
												navigationSeparator0,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addGap(18, 18, 18)
										.addComponent(algorithStartButton)
										.addGap(18, 18, 18)
										.addComponent(
												navigationSeparator1,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												14,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addGap(13, 13, 13)
										.addComponent(picturesBeforeLabel)
										.addGap(3, 3, 3)
										.addComponent(pictureBeforeButton)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addComponent(picturesAfterLabel)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addComponent(picturesAftertButton)
										.addGap(7, 7, 7)
										.addComponent(pictureCompareLabel)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addComponent(picturesComparetButton)
										.addContainerGap(16, Short.MAX_VALUE)));

		parametersPanel.setBorder(javax.swing.BorderFactory
				.createTitledBorder("Ocena kontrastu"));

		algorithmParametersText.setEditable(false);
		algorithmParametersText.setEnabled(true);
		algorithmParametersText.setDragEnabled(true);
		algorithmParametersText.setDropTarget(dropTarget);
		algorithmParametersText.setBackground(navigationPanel.getBackground());
		algorithmParametersText.setText("\nPrzed:\nK1=\nK2=\nK3=\nK4=\n\nPo:\nK1=\nK2=\nK3=\nK4=");
		
		javax.swing.GroupLayout parametersPanelLayout = new javax.swing.GroupLayout(
				parametersPanel);
		parametersPanel.setLayout(parametersPanelLayout);
		parametersPanelLayout.setHorizontalGroup(parametersPanelLayout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						parametersPanelLayout.createSequentialGroup()
								.addContainerGap()
								.addComponent(algorithmParametersText)
								.addContainerGap()));
		parametersPanelLayout.setVerticalGroup(parametersPanelLayout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						parametersPanelLayout.createSequentialGroup()
								.addContainerGap()
								.addComponent(algorithmParametersText)
								.addContainerGap()));

		picturesPathPanel.setBorder(javax.swing.BorderFactory
				.createEmptyBorder(1, 1, 1, 1));

		picturesPathLabel.setText("Wybierz plik obrazu");

		picturesPathExplicite.setEditable(false);
		picturesPathExplicite.setBackground(new java.awt.Color(240, 240, 240));

		picturesPathButton.setText("...");
		picturesPathButton
				.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent evt) {
						picturesPathButtonActionPerformed(evt);
					}
				});

		javax.swing.GroupLayout picturesPathPanelLayout = new javax.swing.GroupLayout(
				picturesPathPanel);
		picturesPathPanel.setLayout(picturesPathPanelLayout);
		picturesPathPanelLayout
				.setHorizontalGroup(picturesPathPanelLayout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								picturesPathPanelLayout
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												picturesPathPanelLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addComponent(
																picturesPathLabel)
														.addGroup(
																picturesPathPanelLayout
																		.createSequentialGroup()
																		.addComponent(
																				picturesPathExplicite,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				158,
																				javax.swing.GroupLayout.PREFERRED_SIZE)
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addComponent(
																				picturesPathButton,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				34,
																				javax.swing.GroupLayout.PREFERRED_SIZE)))
										.addContainerGap(20, Short.MAX_VALUE)));
		picturesPathPanelLayout
				.setVerticalGroup(picturesPathPanelLayout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								picturesPathPanelLayout
										.createSequentialGroup()
										.addComponent(picturesPathLabel)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
										.addGroup(
												picturesPathPanelLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(
																picturesPathExplicite,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																picturesPathButton))
										.addGap(0, 11, Short.MAX_VALUE)));

		fileMenu.setText("Plik");

		newWindowMEnuItem.setText("Nowe okno");
		newWindowMEnuItem
				.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent evt) {
						newWindowMEnuItemActionPerformed(evt);
					}
				});
		fileMenu.add(newWindowMEnuItem);

		saveAfterMenuItem.setText("Zapisz pliki po obróbce");
		fileMenu.add(saveAfterMenuItem);

		exitMenuItem.setText("Wyjście");
		exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				exitMenuItemActionPerformed(evt);
			}
		});
		fileMenu.add(exitMenuItem);

		mainMenuBar.add(fileMenu);

		//picturesMenu.setText("Obrazy");
		//mainMenuBar.add(picturesMenu);

		helpMenu.setText("Help");
		
		FAQMenuItem.setText("FAQ");
		helpMenu.add(FAQMenuItem);

		teamMembersMenuItem.setText("Skład zespołu");
		helpMenu.add(teamMembersMenuItem);

		instructionMenuItem.setText("Instrukcja obsługi programu");
		instructionMenuItem
				.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent evt) {
						try {
						Process p=Runtime.getRuntime().exec("explorer "+  new java.io.File( "../doc" ).getCanonicalPath()); 
						p.waitFor();
						} catch (InterruptedException | IOException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} 
					}
				});
			
		helpMenu.add(instructionMenuItem);
		
		documentationMenuItem.setText("Dokumentacja projektu");
		helpMenu.add(documentationMenuItem);
		documentationMenuItem.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				try {
				Process p=Runtime.getRuntime().exec("explorer "+ "http://code.google.com/p/cpoo-contrast-improvment/"); 
				p.waitFor();
				} catch (InterruptedException | IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} 
			}
		});
		mainMenuBar.add(helpMenu);

		setJMenuBar(mainMenuBar);
		setDropTarget(dropTarget);
		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
				getContentPane());
		
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addComponent(navigationPanel,
										javax.swing.GroupLayout.PREFERRED_SIZE,
										javax.swing.GroupLayout.DEFAULT_SIZE,
										javax.swing.GroupLayout.PREFERRED_SIZE)
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.LEADING)
												.addComponent(
														parametersPanel,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														Short.MAX_VALUE)
												.addComponent(
														picturesPathPanel,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														Short.MAX_VALUE))));
		layout.setVerticalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addComponent(navigationPanel,
						javax.swing.GroupLayout.DEFAULT_SIZE,
						javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
				.addGroup(
						layout.createSequentialGroup()
								.addComponent(parametersPanel,
										javax.swing.GroupLayout.DEFAULT_SIZE,
										javax.swing.GroupLayout.DEFAULT_SIZE,
										Short.MAX_VALUE)
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addComponent(picturesPathPanel,
										javax.swing.GroupLayout.PREFERRED_SIZE,
										javax.swing.GroupLayout.DEFAULT_SIZE,
										javax.swing.GroupLayout.PREFERRED_SIZE)
								.addContainerGap()));

		pack();
	}// </editor-fold>//GEN-END:initComponents

	private void instructionMenuItemActionPerformed(
			java.awt.event.ActionEvent evt) {// GEN-FIRST:event_instructionMenuItemActionPerformed
		/*
		 * Kosmetyka zajme sie wolna chwila
		 */
	}// GEN-LAST:event_instructionMenuItemActionPerformed

	private void picturesPathButtonActionPerformed(
			java.awt.event.ActionEvent evt) {// GEN-FIRST:event_picturesPathButtonActionPerformed
		JFileChooser picturesPathChooser = new JFileChooser();
		picturesPathChooser.setCurrentDirectory(new File("."));
		picturesPathChooser.setAcceptAllFileFilterUsed(false);
		picturesPathChooser.addChoosableFileFilter(imageFileter);
		picturesPathChooser.setLocation(150, 150);
		picturesPathChooser.showOpenDialog(null);
		picturesPathChooser.setMultiSelectionEnabled(true);
		File pictureFile = picturesPathChooser.getSelectedFile();
		if (pictureFile != null) {
                        picturesList.clear();
			picturesList.add(pictureFile);
			//JRadioButtonMenuItem pic = new JRadioButtonMenuItem(
			//		pictureFile.toString());
		//	picturesMenu.add(pic);
			String path = pictureFile.getAbsolutePath();
			picturesPathExplicite.setText(path);
		}
		image = null;
		try {
		    image = ImageIO.read(pictureFile);
		} catch (IOException e) {
		}
	}// GEN-LAST:event_picturesPathButtonActionPerformed

	private void newWindowMEnuItemActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_newWindowMEnuItemActionPerformed
		MainWindow newMainWindow = new MainWindow();
	}// GEN-LAST:event_newWindowMEnuItemActionPerformed

	private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_exitMenuItemActionPerformed
		this.dispose();
	}// GEN-LAST:event_exitMenuItemActionPerformed

	private void dropedFile(DropTargetDropEvent evt)
	{
		 try { //not sure if it works on Linux/Unix
	            evt.acceptDrop(DnDConstants.ACTION_COPY);
	            List<File> droppedFiles = (List<File>)
	                evt.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
	           File pictureFile= droppedFiles.get(0);

	           if (imageFileter.accept(pictureFile))
	           {
                   picturesList.clear();
                   picturesList.add(pictureFile);
                 //JRadioButtonMenuItem pic = new JRadioButtonMenuItem(
       			//		pictureFile.toString());
                   String path = pictureFile.getAbsolutePath();
                   picturesPathExplicite.setText(path);
	           }
	           image = null;

	        	   image = ImageIO.read(pictureFile);

	            
	        } catch (Exception ex) {
	            ex.printStackTrace();
	        }
	}
	//TODO
	private void algorithStartButtonActionPerformed(
			java.awt.event.ActionEvent evt) {// GEN-FIRST:event_algorithStartButtonActionPerformed
		String item = (String) algorithmChooseComboBox.getSelectedItem();
		Iterator<AlgorithmInterface> itr = algorithmsList.iterator();
		AlgorithmInterface algorithm;
		while (itr.hasNext()) {
			algorithm = itr.next();
			if (item == algorithm.getName()) { //TODO Kangur: process whole array?? or process single file??
				LOGGER.info(item + " found");
				if(picturesList.isEmpty()==false)
				{
					File current=picturesList.get(0);
					BufferedImage im= algorithm.process(current);
					image_pr = im;
					File file;
					if (item=="Clahe")
					{
						file=ClaheInterface.writeImage(im,current.getAbsolutePath()+"_Clahe_processed.png",null);
					}
					else
					{
						file=HistogramEQInterface.writeImage(im,current.getAbsolutePath()+"_HEq_processed.png",null);
					}
					picturesAfterAlgorithmList.clear();
                                        picturesAfterAlgorithmList.add(file); //TODO
				}
			}

		}
		
		int[][][] img1=new int[image.getWidth()][image.getHeight()][3];
		img1=HistogramRate.toArray(image);
		int[][][] img2=new int[image_pr.getWidth()][image_pr.getHeight()][3];
		img2=HistogramRate.toArray(image_pr);
		algorithmParametersText.setText("\nPrzed:\n"+
										"K1= "+HistogramRate.calcK1(img1)+"\n"+
										"K2= "+HistogramRate.calcK2(img1)+"\n"+
										"K3= "+HistogramRate.calcK3(img1)+"\n"+
										"K4= "+HistogramRate.calcK4(img1)+"\n\n"+
										"Po ("+item+"):\n"+
										"K1= "+HistogramRate.calcK1(img2)+"\n"+
										"K2= "+HistogramRate.calcK2(img2)+"\n"+
										"K3= "+HistogramRate.calcK3(img2)+"\n"+
										"K4= "+HistogramRate.calcK4(img2)+"\n"
									   );

		// TODO
		LOGGER.info(algorithmChooseComboBox.getSelectedObjects().toString());

	}// GEN-LAST:event_algorithStartButtonActionPerformed

	private void pictureBeforeButtonActionPerformed(
			java.awt.event.ActionEvent evt) {// GEN-FIRST:event_pictureBeforeButtonActionPerformed
		Iterator<File> itr = picturesList.iterator();
		while (itr.hasNext()) {
			File element = itr.next();
			PictureDisplay m = new PictureDisplay();
            ColorHistogramWindow hist= new ColorHistogramWindow(new ImagePlus(element.toString()));
            Point p=hist.getLocation();
            p.x = p.x + 300;
            hist.setLocation(p);
			m.setImage(element.toString());
		}
	}// GEN-LAST:event_pictureBeforeButtonActionPerformed

	private void picturesComparetButtonActionPerformed(
			java.awt.event.ActionEvent evt) {// GEN-FIRST:event_picturesComparetButtonActionPerformed
		Iterator<File> itrBefore = picturesList.iterator();
		Iterator<File> itrAfter = picturesAfterAlgorithmList.iterator();
		while (itrBefore.hasNext() && itrAfter.hasNext()) {
			File elementBefore = itrBefore.next();
			File elementAfter = itrAfter.next();
			PictureCompare m = new PictureCompare();
			m.setImage(elementBefore.toString(), elementAfter.toString());
		}
	}// GEN-LAST:event_picturesComparetButtonActionPerformed

	private void algorithmChooseComboBoxActionPerformed(
			java.awt.event.ActionEvent evt) {// GEN-FIRST:event_algorithmChooseComboBoxActionPerformed
		/*
		 * 
		 * 
		 * tutaj bindowanie z przyciskiem "Start algorytmu" + odwolanie sie do
		 * klasy algorytm + zbindowanie tekstu np txt z opisem parametrow
		 */
		LOGGER.info((String) algorithmChooseComboBox.getSelectedItem());

		// TODO

	}// GEN-LAST:event_algorithmChooseComboBoxActionPerformed

	private void picturesAftertButtonActionPerformed(
			java.awt.event.ActionEvent evt) {// GEN-FIRST:event_picturesAftertButtonActionPerformed
		Iterator<File> itr = picturesAfterAlgorithmList.iterator();
		while (itr.hasNext()) {
			File element = itr.next();
			PictureDisplay m = new PictureDisplay();
            ColorHistogramWindow hist= new ColorHistogramWindow(new ImagePlus(element.toString()));
            Point p=hist.getLocation();
            p.x = p.x + 300;
            hist.setLocation(p);
			m.setImage(element.toString());
		}
	}// GEN-LAST:event_picturesAftertButtonActionPerformed

	// Variables declaration - do not modify//GEN-BEGIN:variables
	private javax.swing.JMenuItem FAQMenuItem;
	private javax.swing.JButton algorithStartButton;
	private javax.swing.JComboBox algorithmChooseComboBox;
	private javax.swing.JLabel algorithmChooseLabel;
	private javax.swing.JTextArea algorithmParametersText;
	private javax.swing.JMenuItem documentationMenuItem;
	private javax.swing.JMenuItem exitMenuItem;
	private javax.swing.JMenu fileMenu;
	private javax.swing.JMenu helpMenu;
	private javax.swing.JMenuItem instructionMenuItem;
	private javax.swing.JPanel jPanel2;
	private javax.swing.JMenuBar mainMenuBar;
	private javax.swing.JPanel navigationPanel;
	private javax.swing.JSeparator navigationSeparator0;
	private javax.swing.JSeparator navigationSeparator1;
	private javax.swing.JMenuItem newWindowMEnuItem;
	private javax.swing.JPanel parametersPanel;
	private javax.swing.JButton pictureBeforeButton;
	private javax.swing.JLabel pictureCompareLabel;
	private javax.swing.JLabel picturesAfterLabel;
	private javax.swing.JButton picturesAftertButton;
	private javax.swing.JLabel picturesBeforeLabel;
	private javax.swing.JButton picturesComparetButton;
	private javax.swing.JMenu picturesMenu;
	private javax.swing.JButton picturesPathButton;
	private javax.swing.JTextField picturesPathExplicite;
	private javax.swing.JLabel picturesPathLabel;
	private javax.swing.JPanel picturesPathPanel;
	private javax.swing.JMenuItem saveAfterMenuItem;
	private javax.swing.JMenuItem teamMembersMenuItem;
	// End of variables declaration//GEN-END:variables
	
	
	public class MyDropListener implements DropTargetListener{

		@Override
		public void dragEnter(DropTargetDragEvent dtde) {
			
		}

		@Override
		public void dragExit(DropTargetEvent dte) {
			
			
		}

		@Override
		public void dragOver(DropTargetDragEvent dtde) {
	
			
		}

		@Override
		public void drop(DropTargetDropEvent dtde) {
			dropedFile(dtde);
			
		}

		@Override
		public void dropActionChanged(DropTargetDragEvent dtde) {
		
			
		}
	}
		
}



